package com.cb.eduservice.controller;


import com.cb.eduservice.entity.subject.OneSubject;
import com.cb.eduservice.service.EduSubjectService;
import com.cb.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Cebb
 * @since 2020-06-22
 */
@Api(description = "课程管理")

@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    private final EduSubjectService subjectService;

    @Autowired
    public EduSubjectController(EduSubjectService subjectService) {
        this.subjectService = subjectService;
    }

    @ApiOperation("上传excel, 添加课程分类")
    @PostMapping
    public R uploadExcel(MultipartFile file){
        subjectService.saveSubject(file,subjectService);

        return R.ok();
    }

    @ApiOperation("查询所有课程分类 , 树状结构")
    @GetMapping("getAllSubject")
    public R getAllSubject(){
        List<OneSubject> list = subjectService.getAllOneAndTwoSubject();

        return R.ok().data("list", list);
    }

}

